package com.guldan.jaina.utils;

import com.guldan.core.constants.CommonConstant;
import com.guldan.jaina.dto.area.AreaDTO;
import com.guldan.jaina.dto.dictionary.DictionaryDTO;
import com.guldan.mapper.db.entity.Area;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Silas.
 * Date: 2017/2/3
 * Time: 11:13
 */
public class ComUtils {


    //字段类型id，字典列表
    public static volatile Map<Integer, List<DictionaryDTO>> dicMap = new HashMap<>();
    //区划DTO，key：areaid,value:area
    public static volatile Map<Integer, Area> areaMap = new HashMap<>();

    public static Area getAreaById(Integer areaId) {
        return areaMap != null ? areaMap.get(areaId) : null;
    }

    public static boolean setAreaById(Integer areaId, Area area) {
        if (areaMap.containsKey(areaId))
            areaMap.remove(areaId);
        areaMap.put(areaId, area);
        return true;
    }

    public static void init(){
        dicMap = new HashMap<>();
        areaMap = new HashMap<>();
    }


    private static int chineseNums(String str) {
        byte b[] = str.getBytes();
        int byteLength = b.length;
        int strLength = str.length();
        return (byteLength - strLength) / 2;
    }


    //获取失败原因，按照固定宽度填充空白字符
    public static String getFailReasonWithBlank(String oriStr) {
/*
        int a = chineseNums(oriStr);  //中文字符的个数
        a = a * 2 + (oriStr.length() - a);  //总字符数

        String b = "";  //需要填充的空白字符串
        for (int i = 0; i < CommonConstant.CITIZEN_FAILREASON_ONELINE_CHARS_LENGTH - (a % CommonConstant.CITIZEN_FAILREASON_ONELINE_CHARS_LENGTH); i++) {
            b += " ";
        }
        */
        return oriStr + "\r\n";
    }


}
